//文件名
grammar Expr;

//using "antlr4 Expr.g4 -package tour" to generating package tour
//@header {
//package tour;
//}

//start rule
prog: stat+;

stat: expr NEWLINE
    | ID '=' expr NEWLINE
    | NEWLINE
    ;

expr: expr ('*'|'/') expr
    | expr ('+'|'-') expr
    | INT
    | ID
    | '(' expr ')'
    ;

ID: [a-zA-Z]+ ;                     // match identifiers
INT: [0-9]+;                        // match integers
NEWLINE: '\r'? '\n';                // end-statement signal
WS: [ \t]+ -> skip;                 // toss out whitespace
